package com.ruoyi.stuinfo.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.stuinfo.domain.Attendancerecord;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.stuinfo.domain.Abnormalbehaviorreport;
import com.ruoyi.stuinfo.service.IAbnormalbehaviorreportService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 异常处理Controller
 *
 * @author zc
 * @date 2025-05-14
 */
@RestController
@RequestMapping("/stuinfo/abnormalbehaviorreport")
public class AbnormalbehaviorreportController extends BaseController
{
    @Autowired
    private IAbnormalbehaviorreportService abnormalbehaviorreportService;

    /**
     * 查询异常处理列表
     */
    @PreAuthorize("@ss.hasPermi('stuinfo:abnormalbehaviorreport:list')")
    @GetMapping("/list")
    public TableDataInfo list(Abnormalbehaviorreport abnormalbehaviorreport)
    {

        String teacherId=getUsername();
        boolean hasH = teacherId.contains("H");
        boolean hasX = teacherId.contains("X");
        if("admin".equals(teacherId))
        {
            //管理员
            startPage();
            List<Abnormalbehaviorreport> list = abnormalbehaviorreportService.selectAbnormalbehaviorreportList(abnormalbehaviorreport);
            return getDataTable(list);
        }
        else if(hasH)
        {
            //班主任
            teacherId=teacherId.replace("H", "");
            startPage();
            List<Abnormalbehaviorreport> list = abnormalbehaviorreportService.selectAbnormalbehaviorreportList_handteacher(teacherId);
            return getDataTable(list);
        }
        else if(hasX)
        {
            //系主任
            teacherId=teacherId.replace("X", "");
            startPage();
            List<Abnormalbehaviorreport> list = abnormalbehaviorreportService.selectAbnormalbehaviorreportList_Xiteacher(teacherId);
            return getDataTable(list);
        }
        else
        {
            //管理员
            startPage();
            List<Abnormalbehaviorreport> list = abnormalbehaviorreportService.selectAbnormalbehaviorreportList(abnormalbehaviorreport);
            return getDataTable(list);
        }


    }

    /**
     * 导出异常处理列表
     */
    @PreAuthorize("@ss.hasPermi('stuinfo:abnormalbehaviorreport:export')")
    @Log(title = "异常处理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Abnormalbehaviorreport abnormalbehaviorreport)
    {

        String teacherId=getUsername();
        boolean hasH = teacherId.contains("H");
        if("admin".equals(teacherId))
        {
            //管理员
            List<Abnormalbehaviorreport> list = abnormalbehaviorreportService.selectAbnormalbehaviorreportList(abnormalbehaviorreport);
            ExcelUtil<Abnormalbehaviorreport> util = new ExcelUtil<Abnormalbehaviorreport>(Abnormalbehaviorreport.class);
            util.exportExcel(response, list, "异常处理数据");
        }
        else if(hasH)
        {
            //班主任
            teacherId=teacherId.replace("H", "");
            List<Abnormalbehaviorreport> list = abnormalbehaviorreportService.selectAbnormalbehaviorreportList_handteacher(teacherId);
            ExcelUtil<Abnormalbehaviorreport> util = new ExcelUtil<Abnormalbehaviorreport>(Abnormalbehaviorreport.class);
            util.exportExcel(response, list, "异常处理数据");
        }
        else
        {
            //系主任
            teacherId=teacherId.replace("X", "");
            List<Abnormalbehaviorreport> list = abnormalbehaviorreportService.selectAbnormalbehaviorreportList_Xiteacher(teacherId);
            ExcelUtil<Abnormalbehaviorreport> util = new ExcelUtil<Abnormalbehaviorreport>(Abnormalbehaviorreport.class);
            util.exportExcel(response, list, "异常处理数据");
        }

    }

    /**
     * 获取异常处理详细信息
     */
    @PreAuthorize("@ss.hasPermi('stuinfo:abnormalbehaviorreport:query')")
    @GetMapping(value = "/{reportId}")
    public AjaxResult getInfo(@PathVariable("reportId") Long reportId)
    {
        return success(abnormalbehaviorreportService.selectAbnormalbehaviorreportByReportId(reportId));
    }

    /**
     * 新增异常处理
     */
    @PreAuthorize("@ss.hasPermi('stuinfo:abnormalbehaviorreport:add')")
    @Log(title = "异常处理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Abnormalbehaviorreport abnormalbehaviorreport)
    {
        return toAjax(abnormalbehaviorreportService.insertAbnormalbehaviorreport(abnormalbehaviorreport));
    }

    /**
     * 修改异常处理
     */
    @PreAuthorize("@ss.hasPermi('stuinfo:abnormalbehaviorreport:edit')")
    @Log(title = "异常处理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Abnormalbehaviorreport abnormalbehaviorreport)
    {
        return toAjax(abnormalbehaviorreportService.updateAbnormalbehaviorreport(abnormalbehaviorreport));
    }

    /**
     * 删除异常处理
     */
    @PreAuthorize("@ss.hasPermi('stuinfo:abnormalbehaviorreport:remove')")
    @Log(title = "异常处理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{reportIds}")
    public AjaxResult remove(@PathVariable Long[] reportIds)
    {
        return toAjax(abnormalbehaviorreportService.deleteAbnormalbehaviorreportByReportIds(reportIds));
    }
}
